package com.purengage.ipilih;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import com.purengage.ipilih.lib.CustomAdapter;
import com.purengage.ipilih.lib.DBClass;
import com.purengage.ipilih.lib.FileHelper;

import android.app.ListActivity;
import android.content.Intent;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;

public class More extends ListActivity implements OnItemClickListener{
	public ListAdapter adapter;
	private String[] values = new String[] { "Profile", "Points & Redeem",
			"Agenda Kampanye", "Logistik Kampanye", "Kampanye Anda", "Logout" };
	private int[] draw = new int[] { R.drawable.status_b, R.drawable.star_b,
			R.drawable.agenda_b, R.drawable.truck_b, R.drawable.phone_b, R.drawable.logout };
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_more);

		ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();

		for (int i = 0; i < values.length; i++) {
			HashMap<String, Object> map = new HashMap<String, Object>();
			map.put("textMore", values[i]);
			map.put("image", draw[i]);
			list.add(map);
			Log.d("list", String.valueOf(list));
		}

		adapter = new CustomAdapter(this, list, R.layout.list_activity_more,
				new String[] { "image", "textMore" }, new int[] {
						R.id.imageMore, R.id.textMore });
		setListAdapter(adapter);
		getListView().setOnItemClickListener(this);

	}
	


	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {		
		switch (pos) {
		case 0:
			Intent i = new Intent(More.this, Profile.class);
			startActivity(i);
			break;
		case 5:										
			try {
				DBClass db = new DBClass(this);
				db.deleteConf();				
				
				FileHelper f = new FileHelper(getResources().getString(R.string.client_name));
				f.delete("locations");
				
				Intent in = new Intent(More.this, Login.class);
				startActivity(in);
				finish();
				
				Toast.makeText(
						this,
						"Anda berhasil logout/keluar dari aplikasi ini",
						Toast.LENGTH_LONG).show();
				
			} catch (IOException e) {				
				e.printStackTrace();
			}			
			
		default:
			break;
		}
	}
	

}
